<!DOCTYPE html>
<!--试题管理编辑-->
<html>

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
        <script src="/static/js/common.js"></script>

    <link href="../static/js/vue-treeselect/vue-treeselect.css" rel="stylesheet" />
    <script src="../static/js/vue-treeselect/vue-treeselect.js"></script>
</head>

<body>
    <div id="app" v-cloak  class="popupW50">
        <el-form label-position="right" :model="Form" status-icon :rules="rules" ref="ruleForm" label-width="100px"
            size="mini">
            <el-row>
                <el-col :span="11">
                    <div class="elst-select-mini">
                        <el-form-item>
                            <el-input type="text" v-model="Form.QuestionManagementContent" autocomplete="off"
                                size="mini">
                                <template slot="prepend">
                                    {{QuestionManagement.QuestionManagementContent+mark.m}}
                                </template>
                            </el-input>
                            <span class="iputLineMust" v-if="Form.QuestionManagementContent.length<=0">
                                    <!-- 必填项添加 -->
                                         <img src="/static/images/exclamation.png" alt="">
                                    </span>
                                    
                        </el-form-item>
                    </div>
                </el-col>
                <el-col :span="11" :offset="2">
                    <div class="elst-select-mini">
                        <el-form-item>
                            <el-input size="mini">
                                <template slot="prepend">
                                    <div> {{QuestionManagement.QuestionManagementType+mark.m}}</div>
                                </template>
                                <el-select @visible-change="visibleChange" v-model="Form.QuestionManagementType" slot="suffix"
                                    :placeholder="QuestionManagement.QuestionManagementType">
                                    <el-option label="请选择" value=""></el-option>
                                    <el-option v-for="item in QuestionManagementTypeList" :label="item.value"
                                        :value="item.key">
                                    </el-option>
                                </el-select>
                            </el-input>
                        </el-form-item>
                    </div>
                </el-col>
                <el-col :span="11">
                    <div class="elst-select-mini">
                        <el-form-item>
                            <el-input size="mini">
                                <template slot="prepend">
                                    <div> {{QuestionManagement.DegreeOfDifficulty+mark.m}}</div>
                                </template>
                                <el-select @visible-change="visibleChange" v-model="Form.DegreeOfDifficulty" slot="suffix"
                                    :placeholder="QuestionManagement.DegreeOfDifficulty">
                                    <el-option label="请选择" value=""></el-option>
                                    <el-option v-for="item in DegreeOfDifficultyList" :label="item.value"
                                        :value="item.key">
                                    </el-option>
                                </el-select>
                            </el-input>
                        </el-form-item>
                    </div>
                </el-col>
                <el-col :span="11" :offset="2">
                    <div class="elst-select-mini">
                        <el-form-item>
                            <el-input size="mini">
                                <template slot="prepend">
                                    <div> {{QuestionManagement.Courseware+mark.m}}</div>
                                </template>
                                <el-select @visible-change="visibleChange" v-model="Form.Courseware" slot="suffix"
                                    :placeholder="QuestionManagement.Courseware">
                                    <el-option label="请选择" value=""></el-option>
                                    <el-option v-for="item in Courseware" :label="item.value" :value="item.key">
                                    </el-option>
                                </el-select>
                            </el-input>
                        </el-form-item>
                    </div>
                </el-col>
            </el-row>
            <el-row>
                <el-col class="head-tool">
                    <el-button type="primary" @click="UserInput('tj')">{{col.btnAddItem}}</el-button>
                </el-col>
            </el-row>
            <el-row>
                <el-col>
                    <el-table :data="Form.OptionsList" border>
                        <el-table-column prop="OptionName" :label="QuestionManagementOption.OptionName">
                        </el-table-column>
                        <el-table-column prop="OptionComment" :label="QuestionManagementOption.OptionComment">
                        </el-table-column>
                        <el-table-column prop="" align="center" label="答案">
                            <template slot-scope="scope">
                                <el-select @visible-change="visibleChange" @change="handleSelect" v-model="scope.row.IsAnswer" placeholder="请选择">
                                    <el-option v-for="item in QuestionManagementOptionsList" :key="item.key"
                                        :label="item.value" :value="item.key"></el-option>
                                </el-select>
                            </template>
                        </el-table-column>

                        <el-table-column label="操作">
                            <template slot-scope="scope">
                                <el-button @click.native.prevent="deleteRow(scope.$index, Form.OptionsList)" type="text"
                                    size="small">
                                    移除
                                </el-button>
                            </template>
                        </el-table-column>
                    </el-table>
                </el-col>
            </el-row>
            <br>
            <el-row type="flex" justify="end">
                <el-form-item>
                    <el-button type="primary" @click="onSubmitForm('ruleForm')">{{col.btnSave}}</el-button>
                    <el-button type="primary" @click="onSubmitForm('ruleForm')">{{col.btnCommit}}</el-button>
                    <el-button type="primary" @click="parent.ListItem.dialogVisible=false">{{col.btnBack}}</el-button>
                </el-form-item>
            </el-row>
        </el-form>
        <el-dialog title="试题选项" fullscreen="true" :visible.sync="ListItem.dialogVisible" @close='closeDialog' width="50%" height="50%"
            top="10vh">
            <iframe ref="iframe" :src="ListItem.InputUrl" style="height:280px;width:100%" frameborder="0"></iframe>
        </el-dialog>
    </div>
    <script type="text/javascript">
        Vue.component('treeselect', VueTreeselect.Treeselect)
        var app = new Vue({
            el: '#app',
            data: {
                id: '',
                //业务表单内容
                Form: {
                    id: guidEmpty,
                    QuestionManagementContent: '',//"试题内容"
                    QuestionManagementType: '', //试题类型
                    DegreeOfDifficulty: '',//难易程度
                    Answer: '',//答案
                    Courseware: '',
                    editorTime: '',
                    CoursewareID: null,//课件类型ID
                    OptionsList: [],//选项
                    pid: null

                },
                ListItem: ListItem,
                options: [],
                QuestionManagementOptionsList: [],
                mydata: QuestionManagementTree,
                QuestionManagementTypeList: [],//试题类型
                DegreeOfDifficultyList: [],
                Courseware: [],
                //表单验证
                rules: {
                    PersonnelName: [
                        verification.NotNull,
                        { pattern: verification.StringLengthAtoB.t.format(2, 5), message: verification.StringLengthAtoB.m.format(2, 5), trigger: 'blur' }
                    ],
                    ContractorName: [
                        verification.NotNull,
                        { pattern: verification.StringLengthAtoB.t.format(5, 50), message: verification.StringLengthAtoB.m.format(5, 10), trigger: 'blur' }
                    ],

                }
            },
            methods: {
                //解決edge下select bug
                visibleChange: function (isVisible) {
                    visibleChange(isVisible)
                },
                handleChange: function (value) {
                    console.log(value);
                },
                handleSelect: function (ev) {
                    console.log(ev);
                },
                deleteRow: function (index, rows) {
                    rows.splice(index, 1);
                },

                //提交数据
                onSubmitForm: function (formName) {
                    var mythis = this;
                    this.$refs[formName].validate(function (valid) {
                        //验证通过
                        if (valid) {
                            onSubmitForm(this, '/api/QuestionManagement/Save', mythis.Form);
                        } else {
                            //验证失败
                            return false;
                        }
                    });
                },
                getData: function () {
                    getData(this, '/api/QuestionManagement/get?id=' + this.id);
                    this.Form.Courseware = this.Form.Courseware + "";
                },

                UserInput: function (val, id) { DialogShow(this, val, "QuestionManagementOptionInput.html", id); },

            },
            mounted: function () {
                var list = getDicDataArray(['50', '28', '55', '27']);
                this.QuestionManagementTypeList = getDicData('28', list);
                this.DegreeOfDifficultyList = getDicData('55', list);
                this.Courseware = getDicData('n91');//编辑人;
                // this.QuestionManagementOptionsList = getDicData('50', list);
                this.options = fn(this.mydata, "0");
                this.id = getUrlParam("id");
                this.getData();
            }
        });
    </script>
</body>

</html>